import 'package:flutter_benchu/utils/commonPkg.dart';

class AppNotifier with ChangeNotifier {
  
  //语言地区
  Locale locale;

  //本地app 版本
  String version = '';
  
  //build 号
  String build = '';

  //当前应用最新版本号
  String lastestVersion = '';

  //用户信息详情
  Map user;
  

  AppNotifier(){
    _init();
  }

  _init() async {
    // 读取缓存 语言
    var language = (cacheModel.language).split('_');
    locale = Locale(language.first, language.last);
    _getAppVersion();
  }

  //获取当前app版本号
  _getAppVersion() async {
    version = await getAppVersion();
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    build = packageInfo.buildNumber;

    Log.v('-----------------');
    Log.v(version);
    Log.v(build);
  }

  // 设置语言
  setLocale(String location) {
    var language = (location).split('_');
    locale = Locale(language.first, language.last);
    notifyListeners();
    cacheModel.language=location;
    cacheModel.setLoaclCache();
  }
  
}
